
***************************************************
* Figure D.2
***************************************************

use "$workdata/hoursofwork", clear /*( see  $data_do/hoursofwork.do ) */
keep if year>=2000 & year<=2006
capture drop age_q
g age_q=floor( (age-floor(age))*12)*(1/12) + floor(age)
keep if age_q>=20 & age_q<30
g e=1
replace month=12 if month==0


capture drop wage_hd*

g wage_hd0=wage==1 & (heltid_deltid!=0 & heltid_deltid!=9 )
g wage_hd1=wage==1 & (heltid_deltid!=0 & heltid_deltid!=9 ) & heltid_deltid!=8
g wage_hd2=wage==1 & (heltid_deltid!=0 & heltid_deltid!=9 ) & heltid_deltid!=8 & heltid_deltid!=7
g wage_hd3=wage==1 & (heltid_deltid!=0 & heltid_deltid!=9 ) & heltid_deltid!=8 & heltid_deltid!=7 & heltid_deltid!=6
g wage_hd4=wage==1 & (heltid_deltid!=0 & heltid_deltid!=9 ) & heltid_deltid!=8 & heltid_deltid!=7 & heltid_deltid!=6  & heltid_deltid!=3 & heltid_deltid!=2 


collapse wage_hd* (sum) e, by( age_q pnr )
keep if age_q>=21 & age_q<29

capture drop age_month_q_y
g age_month_q_y=floor(age_q)
tostring age_month_q_y, replace
capture drop age_month_q_m
g age_month_q_m=(round((age_q-floor(age_q))*12)+1)/100
tostring age_month_q_m, replace
capture drop age_month_q
egen age_month_q=concat(age_month_q_y age_month_q_m)
destring age_month_q, replace
g age0_q=age_q-25
g d=age0_q>=0
g dXage0_q=d*age0_q
g age0_q2=age0_q^2
g dXage0_q2=d*age0_q2
g age0_q3=age0_q^3
g dXage0_q3=d*age0_q3
g age0_q4=age0_q^4
g dXage0_q4=d*age0_q4

capture drop w e2
g w=max(0,(12/13)-abs(age0_q))
g e2=w*e

matrix x = (.,.,.,.)
local stop=3
forvalues l=0/`stop' {

local           cond="age_month_q<24.12  | age_month_q>25.04"
if `l'>=1 local cond="age_month_q<24.12  | age_month_q>25.04"
if `l'>=2 local cond="age_month_q<24.12  | age_month_q>25.02"
if `l'>=3 local cond="age_month_q<=24.12  | age_month_q>=25.01"
if `l'>=4 local cond="age_month_q<=24.12  | age_month_q>=25.01"


reg wage_hd`l' d age0_q dXage0_q  [aw=e2]  if (`cond')  , vce(cluster pnr)
capture drop yhat_wage`l'
predict yhat_wage`l'
quietly su yhat_wage`l' if age0_q==0
local lo=round((r(mean)-0.05)*100)/100
local hi=round((r(mean)+0.05)*100)/100

matrix a=(`l')
matrix b=(_b[d])
matrix c=(_se[d])
matrix d=(_b[_cons])
matrix y = (a,b,c,d)
matrix x = (x\y)


preserve 
collapse wage_hd`l' yhat_wage* [aw=e], by(age_q)
twoway (scatter wage_hd`l' age_q if age_q>=23 & age_q<27, msymbol(oh)) (line yhat_wage`l' age_q if age_q>=23 & age_q<27), xline(24.958333) xlabel(23(1)27) name(reg_wage_hd`l', replace)
restore

}


capture drop x*
svmat x
capture drop ci_lo ci_hi
g ci_lo=x2-1.96*x3
g ci_hi=x2+1.96*x3
capture drop nul
g nul=0 if x1!=.

twoway (rcap ci_hi ci_lo x1 if x2<=3, lwidth(medthin) lcolor(gs4)) ///
       (connect x2 x1, msymbol(o) msize(medlarge) mlcolor(gs1) mfcolor(gs8) lpattern(solid))  ///
	   , scheme(s1mono) legend(off) ylabel(-0.02(0.005)0.005) ytitle("RD Estimates, Employment", height(6)) ///
	   xlabel(0 ">0 h" 1 ">9 h" 2 ">18 h" 3 ">27" ) yline(0, lwidth(vthin) lpattern(solid) lcolor(gs1)) xtitle("Hours of work (no UI)", height(6)) name(figD2, replace)
graph save figD2  $figures/figD2, replace
graph export $figures/figD2.pdf, name(figD2) replace
graph export $figures/figD2.png, name(figD2) replace


***************************************************
* end: Figure D.2
***************************************************
